<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Captcha Operation - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.captcha.operation.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.captcha.operation.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.captcha.introduction.html">Introdu&ccedil;&atilde;o</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.captcha.html">Zend_Captcha</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.captcha.adapters.html">CAPTCHA Adapters</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.captcha.operation" class="section"><div class="info"><h1 class="title">Captcha Operation</h1></div>
    

    <p class="para">
        All <acronym class="acronym">CAPTCHA</acronym> adapter implement
        <span class="classname">Zend_Captcha_Adapter</span>, which looks like the following:
    </p>

    <pre class="programlisting brush: php">
interface Zend_Captcha_Adapter extends Zend_Validate_Interface
{
    public function generate();

    public function render(Zend_View $view, $element = null);

    public function setName($name);

    public function getName();

    public function getDecorator();

    // Additionally, to satisfy Zend_Validate_Interface:
    public function isValid($value);

    public function getMessages();

    public function getErrors();
}
</pre>


    <p class="para">
        The name setter and getter are used to specify and retrieve the
        <acronym class="acronym">CAPTCHA</acronym> identifier.  <span class="methodname">getDecorator()</span> can be used
        to specify a <span class="classname">Zend_Form</span> decorator either by name or returning an
        actual decorator object. The most interesting methods are
         <span class="methodname">generate()</span> and  <span class="methodname">render()</span>.
         <span class="methodname">generate()</span> is used to create the <acronym class="acronym">CAPTCHA</acronym>
        token. This process typically will store the token in the session so that you may compare
        against it in subsequent requests.  <span class="methodname">render()</span> is used to render the
        information that represents the <acronym class="acronym">CAPTCHA</acronym>, be it an image, a figlet, a
        logic problem, or some other <acronym class="acronym">CAPTCHA</acronym>.
    </p>

    <p class="para">
        A typical use case might look like the following:
    </p>

    <pre class="programlisting brush: php">
// Creating a Zend_View instance
$view = new Zend_View();

// Originating request:
$captcha = new Zend_Captcha_Figlet(array(
    &#039;name&#039; =&gt; &#039;foo&#039;,
    &#039;wordLen&#039; =&gt; 6,
    &#039;timeout&#039; =&gt; 300,
));

$id = $captcha-&gt;generate();
echo &quot;&lt;form method=\&quot;post\&quot; action=\&quot;\&quot;&gt;&quot;;
echo $captcha-&gt;render($view);
echo &quot;&lt;/form&gt;&quot;;

// On subsequent request:
// Assume captcha setup as before, the value of $_POST[&#039;foo&#039;]
// would be key/value array: id =&gt; captcha ID, input =&gt; captcha value
if ($captcha-&gt;isValid($_POST[&#039;foo&#039;], $_POST)) {
    // Validated!
}
</pre>

</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.captcha.introduction.html">Introdu&ccedil;&atilde;o</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.captcha.html">Zend_Captcha</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.captcha.adapters.html">CAPTCHA Adapters</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="reference.html">Refer&ecirc;ncia do Zend Framework</a></li>
  <li class="header up"><a href="zend.captcha.html">Zend_Captcha</a></li>
  <li><a href="zend.captcha.introduction.html">Introdu&ccedil;&atilde;o</a></li>
  <li class="active"><a href="zend.captcha.operation.html">Captcha Operation</a></li>
  <li><a href="zend.captcha.adapters.html">CAPTCHA Adapters</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>